<template>
  <div>
    <transition :name="transitionName">
      <navigation>
        <router-view/>
      </navigation>
    </transition>
  </div>
</template>

<script>
  export default {
    name: 'App',
    data () {
      return {
        transitionName: ''
      }
    },
    mounted () {
      this.$navigation.on('forward', (to, from) => {
        if (to.route.name == from.route.name || $Util.isNull(from.route.name)) {
          this.transitionName = ''
        } else {
          this.transitionName = 'slide-left'
        }
      })
      this.$navigation.on('back', (to, from) => {
        if (to.route.name == from.route.name) {
          this.transitionName = ''
        } else {
          this.transitionName = 'slide-right'
        }
      })
      this.$navigation.on('replace', (to, from) => {
        let tab = this.$refs.tabs
        if (to.route.name == from.route.name || this.$navigation.getRoutes().length == 1) {
          this.transitionName = ''
        } else {
          this.transitionName = tab.current > tab.prev ? 'slide-left' : 'slide-right'
        }
      })
      this.$navigation.on('refresh', (to, from) => {
        this.transitionName = ''
      })
      this.$navigation.on('reset', (to, from) => {
        this.transitionName = ''
      })
    }
  }
</script>

<style>
  .slide-right-enter-active,
  .slide-right-leave-active,
  .slide-left-enter-active,
  .slide-left-leave-active {
    will-change: transform;
    transition: all .5s;
    position: absolute;
  }

  .slide-right-enter {
    opacity: 0;
    transform: translate3d(-100%, 0, 0);
  }

  .slide-right-leave-active {
    opacity: 0;
    transform: translate3d(100%, 0, 0);
  }

  .slide-left-enter {
    opacity: 0;
    transform: translate3d(100%, 0, 0);
  }

  .slide-left-leave-active {
    opacity: 0;
    transform: translate3d(-100%, 0, 0);
  }
</style>
